package com.tsxy.mall.controller.api;

import com.tsxy.mall.entity.Book;
import com.tsxy.mall.service.BookService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.jws.WebParam;
import java.util.List;

@RestController
@RequestMapping("/api/book")
public class APIBookController {
    @Resource
    private BookService bookService;

    @GetMapping("/search")
    public List goSearch(Book book, String firstSortId){
        List list = bookService.search(book,Integer.valueOf(firstSortId));
        return list;
    }

    @GetMapping("/getBySort")
    public List getBook(String firstSortId,String sortId){
        Book book = new Book();
        book.setBookSortId(Integer.valueOf(sortId));
        if ("-1".equals(sortId)){
            return bookService.getBookByFirstId(Integer.valueOf(firstSortId));
        }
        return bookService.search(book,null);
    }

    @GetMapping("/getByFirstId")
    public List getBookByFirstId(String firstSortId) {
        return bookService.getBookByFirstId(Integer.valueOf(firstSortId));
    }

}
